package com.zzptc.shop.servlet;

import com.zzptc.shop.dao.GoodDao;
import com.zzptc.shop.dao.IDAO;
import com.zzptc.shop.vo.Product;
import com.zzptc.shop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ProductViewServlet")
public class ProductViewServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=utf-8");

        String id = request.getParameter("id");
        System.out.println(id);
        //获取商品ID
        int idd = Integer.parseInt(id);
        IDAO idao = new GoodDao();

      Product product = ((GoodDao) idao).getAll(idd);
        request.setAttribute("goodinfo", product);
        //转到显示商品详情的页面去
        request.getRequestDispatcher("product-view.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
